package com.bdsy.business.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.bdsy.business.model.ExpertEval;
import com.bdsy.business.service.ExpertEvalService;
import com.bdsy.business.service.ShopSellInfoService;
import com.bdsy.common.annotation.Json;
import com.bdsy.common.utils.Result;
import com.bdsy.system.annotation.SysLog;
import com.bdsy.system.model.User;

/**
 * 专家评价
 * @author MING
 * @date 2018年4月9日 下午3:44:25
 */
@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class ExpertEvalController {

	@Autowired
	ExpertEvalService expertEvalService;
	
	@Autowired
	ShopSellInfoService shopSellInfoService;
	
	
	@RequestMapping(value = "expertEval")
	public String feedback(Model model,HttpServletRequest request) {
		User user = (User) request.getSession().getAttribute("user");
		List<Map> allShopList = shopSellInfoService.selectAllShopSellInfo();
			if (!allShopList.isEmpty()) {
//				model.addAttribute("user", user);
				model.addAttribute("allShopList", allShopList);
			}
		return "admin/business/expertEval";
	}
	
	
	/**
	 * 查询评价艺术品信息
	 */
	@Json
	@RequestMapping(value = "expertEvalList")
	public Object expertEvalList() {
		Map<String,Object> map = new LinkedHashMap<>();
		List<Map> expertEval = expertEvalService.expertEval();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("data", expertEval);
		return map;
	}
	
	/**
	 * 根据艺术品id查询评价信息
	 */
	@Json
	@RequestMapping(value = "expertEvalById")
	public Object expertEvalById(int shopId) {
		Map<String,Object> map = new LinkedHashMap<>();
		List<Map> expertEvalList = expertEvalService.expertEvalById(shopId);
		map.put("code", 200);
		map.put("msg", "success");
		map.put("data", expertEvalList);
		return map;
	}
	
	/**
	 * 添加评价信息 
	 */
	@Json
	@RequestMapping(value = "addExpertEval")
	public Object addExpertEval(ExpertEval expertEval) {
		boolean result = expertEvalService.insert(expertEval);
		if (result) {
			return Result.ok("添加成功");
		} else {
			return Result.error("添加失败");
		}
	}
	
	/**
	 * 修改评价信息
	 */
	@Json
	@RequestMapping(value = "updateExpertEval")
	public Object updateExpertEval(ExpertEval expertEval) {
		boolean result = expertEvalService.update(expertEval);
		if (result) {
			return Result.ok("修改成功");
		} else {
			return Result.error("修改失败");
		}
	}
	
	/**
	 * 删除评价信息 
	 */
	@Json
	@RequestMapping(value = "deleteExpertEval")
	public Object deleteExpertEval(String pIds) {
		List<String> list = JSON.parseArray(pIds, String.class);
		boolean result = expertEvalService.delete(list);
		if (result) {
			return Result.ok("删除成功");
		} else {
			return Result.error("删除失败");
		}
	}
	
}
